﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICeFramework.Common.Diagnostics;

namespace ICeFramework.Utilities.Text
{
    public class TextParser
    {
        public static bool ReadToken(string text, char[] stopCharacters, ref int position, out string token, out char stopCharacter)
        {
            Assert.ArgumentNotNull(text, "text");
            Assert.ArgumentNotNull(stopCharacters, "stopCharacters");
            token = string.Empty;
            stopCharacter = '\0';
            int length = text.Length;
            int num2 = stopCharacters.Length;
            for (int i = position; i < length; i++)
            {
                for (int j = 0; j < num2; j++)
                {
                    if (text[i] == stopCharacters[j])
                    {
                        token = text.Substring(position, i - position);
                        stopCharacter = text[i];
                        position = i + 1;
                        return true;
                    }
                }
            }
            return false;
        }

        public static bool ReadToken(string text, char stopCharacter, ref int position, out string token)
        {
            Assert.ArgumentNotNull(text, "text");
            token = string.Empty;
            int length = text.Length;
            for (int i = position; i < length; i++)
            {
                if (text[i] == stopCharacter)
                {
                    token = text.Substring(position, i - position);
                    position = i + 1;
                    return true;
                }
            }
            return false;
        }
    }
}
